import { Route } from 'react-router';
import { IndexRedirect } from 'react-router';
import { WeaErrorPage, WeaLocaleProvider } from 'ecCom';

import stores from './stores';

import './style/index';
import './util/index';

import Home from './components/Home';
import Demo from './components/Demo';
import CustomerBirthday from './components/CrmBirthday';
import Search from './components/Search';
import ContacterQuery from './components/ContacterQuery';
import ContacterQueryResult from './components/ContacterQueryResult';
import ContacterView from './components/contacter/ContacterView';
import Contact from './components/Contact';
import ContractManage from './components/ContractManage';
import AddCustomer from './components/addCustomer';
import CustomerView from './components/customer/CustomerCard';
import OutResourceView from './components/customer/OutResourceView';
import MineCustomer from './components/MineCustomer';
import SellChanceMain from './components/SellChanceMain';
import SellChanceAdd from './components/sellChance/Form';
import ChanceFormTab from './components/sellChance/FormTab';
import ContractView from './components/contract/ContractView';
import ProductView from './components/product/ProductView';
import SearchQuery from './components/customerSearch/SearchQuery';
import SearchQueryResult from './components/customerSearch/SearchQueryResult';

import ContacterMap from './components/customer/contacterMap';

import HighSeasSettingList from './components/highseas/HighSeasSettingList';
import HighSeasList from './components/highseas/HighSeasList';
import HighSeasApproveList from './components/highseas/HighSeasApproveList';
import BusinessCard from './components/public/BusinessCard';
import APIShow from './components/api/ApiShow';
import APISingleShow from './components/api/ApiSingleShow';
import APIShowGroup from './components/api/apiShowGroup/ApiShowGroup';
import SellchanceView from './components/sellChance/SellchanceView';
import ConditionDialog from './components/dialog/HighSeasConditionDialog';
import ContactImp from './components/contact/ContactImp';
import AddRemindForm from './components/remind/AddRemind';
import RemindList from './components/remind/RemindList';

const getLocaleLabel = WeaLocaleProvider.getLocaleLabel.bind(this, 'crm');
const { getLocaleLabelByCode } = WeaLocaleProvider;

window.crm_store = stores;

class Error extends React.Component {
  render() {
    return (
      <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@ud8r3t`} msg="对不起，无法找到该页面！" />
    );
  }
}

const Routes = (
  <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@oyzn4r`} path="crm" name="crm" breadcrumbName="客户" onEnter={getLocaleLabel} component={Home}>
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@q1js28`} name="demo" path="demo" breadcrumbName="示例" component={Demo} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@7mxi4s`} name="birthday" path="birthday" breadcrumbName="客户生日" component={CustomerBirthday} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@4svmer`} name="customer" path="customer/search" breadcrumbName="查询客户" component={SearchQuery} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@xd3rzv`} name="customerSearchResult" path="customer/customerSearchResult" breadcrumbName="查询客户结果页" component={SearchQueryResult} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@9l41jz`} name="customer" path="customer/:type" breadcrumbName="客户监控,客户分配 ,批量共享" component={Search} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@9htx2x`} name="contacterSearch" path="contacterSearch" breadcrumbName="查询联系人" component={ContacterQuery} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@qq3xai`} name="contacterSearchResult" path="contacterSearchResult" breadcrumbName="查询联系人结果" component={ContacterQueryResult} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@t2g625`} name="contacterView" path="contacterView" breadcrumbName="联系人卡片" component={ContacterView} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@r3gkle`} name="contact" path="contact" breadcrumbName="客户联系" component={Contact} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@ihntat`} name="contactImp" path="contactImp" breadcrumbName="客户联系导入" component={ContactImp} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@mc58v6`} name="contract" path="contract" breadcrumbName="合同管理" component={ContractManage} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@ndie5m`} name="addCustomer" path="addCustomer" breadcrumbName="新建客户" component={AddCustomer} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@9iriry`} name="customerView" path="customerView" breadcrumbName="客户卡片" component={CustomerView} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@hwf9am`} name="outinterfaceview" path="outinterfaceview" breadcrumbName="外部用户卡片" component={OutResourceView} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@4q280c`} name="mineCustomer" path="mineCustomer" breadcrumbName="我的客户" component={MineCustomer} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@dou8g9`} name="sellChance" path="sellChance" breadcrumbName="商机管理" component={SellChanceMain} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@ptqgbq`} name="sellChanceAdd" path="sellChanceAdd" breadcrumbName="商机管理新建" component={SellChanceAdd} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@iw7ny3`} path="chanceView/:customerid/:selectedKey/:sellChanceId" component={ChanceFormTab} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@5o50nx`} name="sellchanceView" path="sellchanceView" component={SellchanceView} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@5uascw`} name="contractView" path="contractView" breadcrumbName="合同卡片" component={ContractView} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@6eztvz`} name="productView" path="productView" breadcrumbName="产品卡片" component={ProductView} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@u36h82`} name="contacterMap" path="contacterMap" breadcrumbName="联系人图谱" component={ContacterMap} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@5pjmck`} path="api">
      <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@x0m167`} path="APIShow/:module" name="APIShow" breadcrumbName="多个API分组展示" component={APIShow} />
      <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@7k5zcq`} path="APISingleShow/:frontPath" name="APISingleShow" breadcrumbName="单个API展示" component={APISingleShow} />
      <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@os0eb0`} path="APIShowGroup/:module" name="APIShowGroup" breadcrumbName="多个API按分组展示" component={APIShowGroup} />
    </Route>
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@yn0h2t`} path="highseas" name="highseas">
      <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@s75dd6`} path="settinglist" breadcrumbName="公海设置" component={HighSeasSettingList} />
      <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@th82eu`} name="seasList" path="seasList" breadcrumbName="客户公海" component={HighSeasList} />
      <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@2h4m2m`} name="approveList" path="approveList" breadcrumbName="客户审批" component={HighSeasApproveList} />
    </Route>
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@yvr1um`} name="addRemind" path="addRemind" breadcrumbName="新建提醒" component={AddRemindForm} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@ipat3q`} name="remindList" path="remindList" breadcrumbName="PC端提醒列表" component={RemindList} />
    <Route ecId={`${this && this.props && this.props.ecId || ''}_Route@m2c1af`} path="*" component={Error} />
  </Route>
);

import { Provider } from 'mobx-react';

class BusinessCardProvider extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      reRender: false,
    };
  }
  componentDidMount() {
    // 多语言加载之后，已经 mount 的组件，需要重新 render 一次，刷新多语言配置。
    getLocaleLabelByCode('crm').then(() => this.setState({ reRender: true }));
  }
  render() {
    return <Provider ecId={`${this && this.props && this.props.ecId || ''}_Provider@ohcjsb`} {...stores}><BusinessCard ecId={`${this && this.props && this.props.ecId || ''}_BusinessCard@rki9bd`} {...this.props} /></Provider>;
  }
}

class ConditionDialogProvider extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      reRender: false,
    };
  }
  componentDidMount() {
    // 多语言加载之后，已经 mount 的组件，需要重新 render 一次，刷新多语言配置。
    getLocaleLabelByCode('crm').then(() => this.setState({ reRender: true }));
  }
  render() {
    return <Provider ecId={`${this && this.props && this.props.ecId || ''}_Provider@nf21lw`} {...stores}><ConditionDialog ecId={`${this && this.props && this.props.ecId || ''}_ConditionDialog@otk66d`} {...this.props} /></Provider>;
  }
}

module.exports = {
  Route: Routes,
  store: stores,
  com: {
    BusinessCard: BusinessCardProvider,
    ConditionDialog: ConditionDialogProvider,
  },
};

